package com.tedu.review.test;

/**
 * equals方法
 * 测试类：China类---属性：city county
 */
public class Object判断 {
    public static void main(String[] args) {
        //创建两个china类
        China c1=new China();

        c1.city="唐山";
        c1.county="曹妃甸";

        System.out.println(c1);

        China c2=new China();
        System.out.println(c2);

        c2.city="唐山";
        c2.county="曹妃甸";

        System.out.println(c1.equals(c2));
    }
    static class China{
        public String city;
        public String county;
      //重写equals方法  判断china中市和县是否相等
        public  boolean equals(Object o){
//①将object超类 强转为China:向下造型
            China china=(China) o;
//@China对象拿到调属性:city county
        boolean c=this.city.equals(china.city);
//当前China对象的city属性与拿到China参数中city对比

            boolean y=this.county.equals(china.county);
           //两两对比之后，全部都是正确 弹出 true	否则 false
            return c&&y;
        }
    }



}
